<?php
/*
 +----------------------------------------------------------------------
 + Title        : ApiChannel 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2019/5/31 17:51
 + Last-time    : 2019/5/31 17:51+ 86187
 + Desc         : ApiChannel
 +----------------------------------------------------------------------
*/


namespace app\admin\controller;


use library\Controller;
use think\facade\Cache;

class ApiChannel extends Controller
{
    use \app\common\traits\controller\Controller;
    protected $table = 'api_channel';

    /**
     * 列表
     *
     * @auth   true
     * @menu   true
     * @return mixed
     * @author : Randy_chen
     * @Date   : 2019/7/13
     * @Time   : 10:57
     */
    public function index()
    {
        $this->title = '渠道商管理';
        if ($this->request->isPost()) {
            $res = $this->_query($this->table)
                        ->order('id desc')
                        ->page(true, false, '', request()->param('limit'));
            $res['data'] = $res['list'];
            $this->success('查询成功!', $res);
        } else {
            $this->applyCsrfToken();
            return $this->fetch();
        }
    }

    public function _form_filter(&$data)
    {
        if (request()->isPost()) {
            $service = new \app\api\service\ApiChannel();
            if (!$data['channel_id']) $data['channel_id'] = $service->set_channel_id();
            if (!$data['channel_key']) $data['channel_key'] = $service->set_channel_key();
            $key = 'CHANNEL:' . $data['channel_id'];
            Cache::rm($key);
        }
    }


}